package br.com.atid.model.graphicalNetElements
{
	import br.com.atid.model.entity.Arc;
	import br.com.atid.util.Utils;
	import br.com.atid.view.util.GraphicsUtil;
	
	import flash.display.Shape;
	import flash.geom.Point;
	
	import mx.collections.ArrayCollection;
	import mx.core.UIComponent;
	
	import spark.components.Group;
	import flash.events.Event;

	public class GraphicalArc extends Group implements INameable
	{
		private var _arc:Arc;
		private var _destinationPoint:Point;
		private var _sourcePoint:Point;
		private var shapeArrow:UIComponent;
		private var deadzoneMultiplier:Number=30;
		private var _showName:Boolean;
		private var _selected:Boolean;

		public function GraphicalArc(id:String, name:String, source:IGraphicalNetElement, destination:IGraphicalNetElement=null, firstElement:Boolean=false)
		{
			this.shapeArrow=new UIComponent();
			this.addElement(this.shapeArrow);

			_arc=new Arc(id, name, source, destination);

			//super('name', false, firstElement);

			//super.type=_arc.type;
//			if (!this.first)
//			{
//				this.addChild(super.selectedShape);
//			}
//			this.addChild(super.deadZone);
		}

		public function updateName():void
		{
			//this.
		}


		public function drawArc(sourcePoint:Point, destPoint:Point, first:Boolean = false):void
		{
			this.destinationPoint=destPoint;
			this.sourcePoint=sourcePoint;
			Utils.drawArcArrow(this.shapeArrow, sourcePoint, destPoint, first);
		}

		private function drawSelectShape(destPoint:Point):void
		{
//			if (!this.first)
//			{
//				Utils.drawSelectShapeArcArrow(super.selectedShape, new Point(arc.source.x, arc.source.y), destPoint);
//			} //drawDeadzone(destPoint);
		}

		public function get arc():Arc
		{
			return _arc;
		}

		public function set arc(value:Arc):void
		{
			_arc=value;
		}

		public function get incomingArcs():ArrayCollection
		{
			return null;
		}

		public function set incomingArcs(value:ArrayCollection):void
		{
			//_incomingArcs = value;
		}

		public function get outcomingArcs():ArrayCollection
		{
			return null;
		}

		public function set outcomingArcs(value:ArrayCollection):void
		{
			//_outcomingArcs = value;
		}

		[Bindable(event="showNameChange")]
		public function get showName():Boolean
		{
			return _showName;
		}

		public function set showName(value:Boolean):void
		{
			if( _showName !== value)
			{
				_showName = value;
				dispatchEvent(new Event("showNameChange"));
			}
		}

		[Bindable(event="destinationPointChange")]
		public function get destinationPoint():Point
		{
			return _destinationPoint;
		}

		public function set destinationPoint(value:Point):void
		{
			if( _destinationPoint !== value)
			{
				_destinationPoint = value;
				dispatchEvent(new Event("destinationPointChange"));
			}
		}

		[Bindable(event="sourcePointChange")]
		public function get sourcePoint():Point
		{
			return _sourcePoint;
		}

		public function set sourcePoint(value:Point):void
		{
			if( _sourcePoint !== value)
			{
				_sourcePoint = value;
				dispatchEvent(new Event("sourcePointChange"));
			}
		}

		[Bindable]
		public function get selected():Boolean
		{
			return _selected;
		}

		public function set selected(value:Boolean):void
		{
			_selected = value;
		}


//		override public function set selected(value:Boolean):void
//		{
//			super.selected=value;
//			this.shapeArrow.visible=!value;
//		}
	}
}
